package com.spoxcy.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBUtil {

    private String db_connector;
    private String db_url;
    private String db_username;
    private String db_password;

    //Method that returns a connector that uses JDBC connection to database
    public Connection getConnection() {
        Connection c = null;
        try {
            Class.forName(this.db_connector);
            c = DriverManager.getConnection(this.db_url, this.db_username, this.db_password);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return c;
    }

    public String getDb_connector() {
        return db_connector;
    }

    public void setDb_connector(String db_connector) {
        this.db_connector = db_connector;
    }

    public String getDb_password() {
        return db_password;
    }

    public void setDb_password(String db_password) {
        this.db_password = db_password;
    }

    public String getDb_url() {
        return db_url;
    }

    public void setDb_url(String db_url) {
        this.db_url = db_url;
    }

    public String getDb_username() {
        return db_username;
    }

    public void setDb_username(String db_username) {
        this.db_username = db_username;
    }

    //Tester
    public static void main(String[] args) {
        DBUtil dbUtility = new DBUtil();
        dbUtility.setDb_connector("com.mysql.jdbc.Driver");
        dbUtility.setDb_url("jdbc:mysql://localhost:3306/spoxcy");
        dbUtility.setDb_username("root");
        dbUtility.setDb_password("root");
        Connection c = dbUtility.getConnection();
        System.out.println(c);
    }
}
